using System;
using System.Collections.Generic;

namespace MySpreadsheet
{
    public static class Extensions
    {
        public static IEnumerable<T> ForEach<T>(this IEnumerable<T> source, Action<T> act)
        {
            foreach (T element in source) act(element);
            return source;
        }

        public static IEnumerable<T> Even<T>(this IEnumerable<T> source)
        {
            bool even = true;
            foreach (T element in source)
            {
                if (even) yield return element;
                even = !even;
            }
        }

        public static IEnumerable<T> Odd<T>(this IEnumerable<T> source)
        {
            bool odd = false;
            foreach (T element in source)
            {
                if (odd) yield return element;
                odd = !odd;
            }
        }
    }
}